<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

 defined('_JEXEC') or die('Retricted Access');
  
global $jbconfig;
?>
<script type="text/javascript">
	/* <![CDATA[ */    
    function submitbutton(pressbutton){
		if(pressbutton == "sendemail"){
			var sendmail = document.getElementById("sendmail");
			sendmail.style.display = "block";
		} else {
			form.task.value = pressbutton;
			form.submit();
		}
    }   
    /* ]]> */
</script>

<div id="jobboard-content">
<form action="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&layout=my-applications'); ?>" method="post" name="adminForm" id="adminForm">
	<div id="ja-applications-top">
		<div class="apply-top-left">
			<label><?php echo JText::_('Applications History')?></label>
		</div>
		<div class="apply-top-right">
			<label><?php echo JText::_('Created Date')?></label>
		</div>
	</div>
	
	<?php if ($this->items){?>
		<div id="ja-list-applications">
		<?php foreach ($this->items as $item){
			JFilterOutput::objectHTMLSafe( $item );
//			$item->message = str_replace('&#039;','\'',$item->message);
			$item->message = htmlspecialchars_decode ( $item->message );
		?>	
				<?php if($item->user_id) {
                    	$resume_user = JFactory::getUser($item->user_id);
                    	$resume_name = $resume_user->name;
                    	$resume_email =  $resume_user->email;   
                    	$resume_alias = JFilterOutput::stringURLSafe($resume_user->name);    
                    }else{
                    	$resume_name = $item->guest_name;
                    	$resume_email =  $item->guest_email;
                    	$resume_alias = '';   
                    } 
                    
                    $resume = getItemByFieldName('ja_resumes','user_id',$item->user_id);                                   
                 ?>
                 
				<div class="ja-application clearfix">
				  <div class="ja-letter">
						<p>
							<?php $alias = JFilterOutput::stringURLSafe($item->job_id); ?>                    	
							<span class="apply-subject">
								<img alt="avatar" src="<?php if($resume && isset($resume[0]->image) && $resume[0]->image!='') echo $resume[0]->image; else echo JURI::base().'components/com_jajobboard/images/noavatar.png';?>" style="float: left; padding-right: 7px;"/>
								<i>
									<?php if ($resume) {?>
                            			<a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaresumes&layout=jaview&cid[]='. $resume[0]->id.'&alias='.$resume_alias.'&Itemid=1000'); ?>">
                            		<?php }?>
											<?php echo $resume_name?> 
									<?php if ($resume) {?>
										</a>
									<?php }?>
									 (<?php echo $resume_email?>)
								</i>
								<br/>
								<?php echo JText::_('Apply for Job')?>: <i><a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jajobs&layout=jaview&cid[]='.$item->job_id_tmp.'&alias='.$alias.'&Itemid=1000')?>" id="goto_job_<?php echo $item->job_id_tmp?>"><?php echo $item->job_id; ?></a></i>
								<p></p>
								<b><?php echo JFilterInput::_decode($item->subject, 'string')?></b>
							</span>:
							<span class="apply-body">
								<?php 
									if ($item->apply_type==3) echo $item->message;
									elseif($item->apply_type==2){
										echo JText::_('Information link');
										echo ' <a target="_blank" href="'.$item->inlinked.'">'.$item->inlinked.'</a>';
									}
								?>
							</span>						
						</p>
						<?php if($item->attachment){ ?>
	                         <?php echo JText::_('Attached'); ?>:
	                         <?php 
			                       $ext = strtolower(substr($item->attachment, -3, 3));			                       
			                       if(!file_exists(JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'images'.DS.'icons'.DS.'applications'.DS.$ext.'.gif')){
			                       		$ext = 'unknow';
			                       }
			                       $file_name = explode('/',$item->attachment);
		                       ?>
	                         <img src="components/com_jajobboard/images/icons/applications/<?php echo $ext?>.gif" alt="thumbnail"/>
	                         <a href ="#" onclick="location.href='index.php?option=com_jajobboard&amp;view=jaapplications&amp;task=download&amp;cid[]=<?php echo $item->id?>'">
	                       		  <?php echo substr($file_name[count($file_name)-1],14);?>	                         
	                       	 </a> 
                      	<?php }  ?>
                   	
					</div>
					<div class="apply-time">
						<?php echo date(str_replace('%', '', $jbconfig['general']->get('format_date')), strtotime($item->created_date));?>
					
					</div>
				 	<div class="application-button">
						<img title="<?php echo JText::_('Delete'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_delete.gif' ?>" alt="<?php echo JText::_('Delete'); ?>" />
		               &nbsp;
		                <a onclick="return confirm('<?php echo JText::_('Are you sure to delete this item?')?>')" href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jaapplications&task=empployer_remove&cid='.$item->id.'&Itemid='.JRequest::getVar('Itemid')); ?>">
		               		<span style="vertical-align: top !important;"><?php echo JText::_('Delete'); ?></span>
		               	</a>
					</div>  	
				</div>
				
		<?php }?>
				<div align="center">
					<?php echo $this->pagination->getListFooter(); ?>
				</div>
		</div>
		
	<?php
	}
	else 
	{
		echo JText::_('No application found for your posted jobs');
		?>
		<a class="button" href="javascript:window.history.go(-1);"><?php echo JText::_('Back'); ?></a>
		<?php
	}
	?>
	
	
	<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
	<input type="hidden" name="view" value="jaapplications" />
	<input type="hidden" name="layout" value="jaempllist" />
	<input type="hidden" name="job_id" value="<?php echo JRequest::getVar('job_id', ""); ?>" />
    <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
    <input type="hidden" name="limited" value="<?php echo $limited; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
</div>	